Page({
  data: {
    userId: '',
    password: '',
    loading: false,
    userAccountShow: false,
    switchText: '手机验证登录 >'
  },

  tabClick(e) {
    this.setData({
      userAccountShow: +e.currentTarget.id === 0,
      switchText: +e.currentTarget.id !== 0 ? '账号密码登录 >' : '手机验证登录 >'
    });
  },
  onLoad() {
    this.setData({
      userAccountShow: true
    });
  },

  getValid(){
    console.log('获取验证码')
  },
  
  bindChange: function (e) {
    if (e.currentTarget.id === 'account') {
      this.setData({
        userId: e.detail.value
      });
    } else if (e.currentTarget.id === 'password') {
      this.setData({
        password: e.detail.value
      });
    }
  },

  //'https://api.hibai.cn/api/index/index', 测试URL
  //登陆入口
  onLogin: function (e) {
    /******************测试入口，发布前需删除******************* */
    wx.redirectTo({
      url: '/pages/home/home'
    });
    return;
    /*********************************************************/
    //此处调用后台接口进行登录操作，参数: data.userId, data.password
    wx.request({
      url: 'http://10.10.11.58:8101/archermind-ai/login',
      data: {
        'userName': this.data.userId,
        'passWord': this.data.password
      },
      method: 'POST',
      header: {
        'content-type': 'application/x-www-form-urlencoded'
      },
      success(res) {
        console.log(res.data)
        //登录成功，跳转首页
        wx.redirectTo({
          url: '/pages/home/home'
        });
      },
      fail(err) {
        wx.showToast({
          title: '账号或密码错误！',
          icon: 'loading',
          duration: 1000,
          mask: true
        });
      }
    })
  }
})